﻿package mortal.game.scene3D.display3d.blood
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import com.mui.core.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.core.*;
    import frEngine.math.*;
    import frEngine.shader.filters.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.*;
    import mortal.game.scene3D.display3d.blood.bossBlood.*;
    import mortal.game.scene3D.display3d.blood.monsterBlood.*;
    import mortal.game.scene3D.display3d.blood.otherPlayerBlood.*;
    import mortal.game.scene3D.display3d.blood.petBlood.*;
    import mortal.game.scene3D.display3d.blood.physical.*;
    import mortal.game.scene3D.display3d.blood.roleBlood.*;
    import mortal.game.scene3D.layer3D.utils.*;

    public class Blood3DResource extends Object
    {
        public var surface5:FrSurface3D;
        public var surface100:FrSurface3D;
        public var surface100_2:FrSurface3D;
        public var blood3dTexture:Texture3D;
        public var smallBg:Texture3D;
        public var smallTop:Texture3D;
        public static var instance:Blood3DResource = new Blood3DResource;

        public function Blood3DResource()
        {
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            var _loc_2:* = ResourceConst.getScaleBitmap(ImagesConst.lifeBg, 10, 250, 64, 8, null);
            var _loc_3:* = ResourceConst.getScaleBitmap(ImagesConst.lifeTop, 10, 100, 64, 8, null);
            var _loc_4:* = GlobalClass.getBitmapData(ImagesConst.blood3d);
            this.smallBg = new Texture3D(_loc_2.bitmapData, 0, 0);
            this.smallTop = new Texture3D(_loc_3.bitmapData, 0, 0);
            this.blood3dTexture = new Texture3D(_loc_4, 0, 0);
            this.smallBg.immediatelyUpload();
            this.smallTop.immediatelyUpload();
            this.blood3dTexture.immediatelyUpload();
            this.surface5 = this.createBloodsSurface(12, 200, 24);
            this.surface100 = this.createBloodsSurface(100, 60, 8);
            this.surface100_2 = this.createBloodsSurface(100, 132, 24);
            PetBlood3DRender.instance.init(param1);
            RoleBlood3DRender.instance.init(param1);
            MonsterBlood3DRender.instance.init(param1);
            OPlayerBlood3DRender.instance.init(param1);
            BossBlood3DRender.instance.init(param1);
            PhysicalPowerRender.instance.init(param1);
            return;
        }// end function

        public function reinit(param1:GameScene3D) : void
        {
            this.surface5.reUpload();
            this.surface100.reUpload();
            this.surface100_2.reUpload();
            this.smallBg.reUpload();
            this.smallTop.reUpload();
            this.blood3dTexture.reUpload();
            return;
        }// end function

        public function createBlood3D(param1:int) : Blood3D
        {
            var _loc_2:Blood3D = null;
            switch(param1)
            {
                case EBloodType.Monster:
                {
                    _loc_2 = MonsterBloodFactory.createBlood3D();
                    break;
                }
                case EBloodType.Role:
                {
                    _loc_2 = RoleBloodFactory.createBlood3D();
                    break;
                }
                case EBloodType.Pet:
                {
                    _loc_2 = PetBloodFactory.createBlood3D();
                    break;
                }
                case EBloodType.OtherPlayer:
                {
                    _loc_2 = OPlayerBloodFactory.createBlood3D();
                    break;
                }
                case EBloodType.Boss:
                {
                    _loc_2 = BossBloodFactory.createBlood3D();
                    break;
                }
                case EBloodType.PhysicalPower:
                {
                    _loc_2 = PhysicalPowerFactory.createBlood3D();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function createBloodsSurface(param1:uint, param2:int, param3:int) : FrSurface3D
        {
            var _loc_4:FrVertexBuffer3D = null;
            var _loc_12:int = 0;
            var _loc_5:* = new FrSurface3D("bloods" + param1);
            _loc_4 = _loc_5.addVertexData(FilterName_ID.POSITION_ID, 3, true, null);
            _loc_5.addVertexDataToTargetBuffer(FilterName_ID.UV_ID, 2, null, _loc_4);
            var _loc_6:* = this.createSinglePlaneVector(param2, param3);
            var _loc_7:* = new Vector.<Number>;
            var _loc_8:* = _loc_5.addVertexData(FilterName_ID.SKIN_INDICES_ID, 1, true, null);
            var _loc_9:* = _loc_8.vertexVector;
            var _loc_10:int = 0;
            while (_loc_10 < param1)
            {
                
                _loc_7 = _loc_7.concat(_loc_6);
                _loc_9.push(_loc_10, _loc_10, _loc_10, _loc_10);
                _loc_10++;
            }
            _loc_4.vertexVector = _loc_7;
            var _loc_11:* = new Vector.<uint>;
            _loc_10 = 0;
            while (_loc_10 < param1)
            {
                
                _loc_12 = _loc_10 * 4;
                _loc_11.push(_loc_12, _loc_12 + 2, (_loc_12 + 1));
                _loc_11.push(_loc_12 + 3, _loc_12 + 2, _loc_12);
                _loc_10++;
            }
            _loc_5.indexVector = _loc_11;
            _loc_4.toUpdate();
            return _loc_5;
        }// end function

        private function createSinglePlaneVector(param1:int, param2:int) : Vector.<Number>
        {
            param1 = param1 / 2;
            param2 = param2 / 2;
            var _loc_3:* = new Vector.<Vector3D>;
            _loc_3.push(new Vector3D(param1, -param2, 0));
            _loc_3.push(new Vector3D(-param1, -param2, 0));
            _loc_3.push(new Vector3D(-param1, param2, 0));
            _loc_3.push(new Vector3D(param1, param2, 0));
            var _loc_4:* = new Vector.<Point>;
            _loc_4.push(new Point(1, 1));
            _loc_4.push(new Point(0, 1));
            _loc_4.push(new Point(0, 0));
            _loc_4.push(new Point(1, 0));
            var _loc_5:* = Scene3DUtil.cameraQuaternion;
            var _loc_6:* = new Vector.<Number>;
            var _loc_7:* = new Vector3D();
            var _loc_8:int = 0;
            while (_loc_8 < 4)
            {
                
                _loc_5.rotatePoint(_loc_3[_loc_8], _loc_7);
                _loc_6.push(_loc_7.x, _loc_7.y, _loc_7.z, _loc_4[_loc_8].x, _loc_4[_loc_8].y);
                _loc_8++;
            }
            return _loc_6;
        }// end function

    }
}
